package com.atguigu.gmallrealtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yhm
 * @create 2023-10-08 15:07
 */
public class KeywordUtil {

    public static ArrayList<String> iKSplitWord(String word) throws IOException {
        ArrayList<String> result = new ArrayList<>();
        StringReader stringReader = new StringReader(word);
        IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);
        Lexeme lexeme = null;
        while ((lexeme = ikSegmenter.next()) != null) {
            result.add(lexeme.getLexemeText());
        }
        return result;
    }

    public static void main(String[] args) throws IOException {
//        StringReader stringReader = new StringReader("Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信4G手机 双卡双待");
//        IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);
//        Lexeme lexeme = null;
//        while ((lexeme = ikSegmenter.next()) != null) {
//            System.out.print(lexeme.getLexemeText() + "\t");
//        }
        ArrayList<String> strings = KeywordUtil.iKSplitWord("Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信4G手机 双卡双待");
        System.out.println(strings);

    }
}
